//
//  ViewController.m
//  04-UIControl
//
//  Created by Snow on 16/7/19.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor blackColor];
    /* 一.UISwitch(开关) */
    UISwitch *swit = [[UISwitch alloc] initWithFrame:CGRectMake(20, 50, 0, 0)];//宽高不影响控件的大小
    //1.开启时的控件内部颜色
    swit.onTintColor = [UIColor yellowColor];
    //2.边框及切换到关闭时的颜色 (null_resetable)
//    swit.tintColor = [UIColor cyanColor];
    swit.tintColor = nil;
    //3.开关按钮的颜色(圆圈的颜色)
    swit.thumbTintColor = [UIColor blackColor];
    //4.打开时的图片 iOS7后失效
    swit.onImage = [UIImage imageNamed:@"u=2836014281,1543658309&fm=23&gp=0.jpg"];
    //5.关闭时的图片 iOS7后失效
    swit.offImage = [UIImage imageNamed:@"u=2992248920,985956402&fm=23&gp=0.jpg"];
    //6.判断switch的开闭状态
    //通过setter方法 改变switch的初始状态
    swit.on = YES;
    NSLog(@"%@", swit.isOn ? @"YES" : @"NO");
    [swit setOn:YES animated:YES];
    //7.添加绑定事件(与button相同)
    [swit addTarget:self action:@selector(switcAction:) forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:swit];
    
    /* 二.UISlider */
    //高度不影响视图的高度 这个控件用于居中与视图中间
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 125, 355, 30)];
    //1.当前滑块的位置
    slider.value = 0.5;
    //2.滑块最大值
    slider.minimumValue = 0;
    //3.滑块最小值
    slider.maximumValue = 1;//可以根据需求改变
    //4.最小值端显示的图片
//    slider.minimumValueImage = [UIImage imageNamed:@"player_slider_playback_left@2x"];
    //5.最大值端显示的图片
//    slider.maximumValueImage = [UIImage imageNamed:@"player_slider_playback_right@2x"];
    //6.continous
    slider.continuous = NO;//yes 的时候 事件随value值改变随时触发 no的时候 只有松开手停止滑动后才触发事件
    //7.绑定事件
    [slider addTarget:self action:@selector(SliderAcion:) forControlEvents:UIControlEventValueChanged];
    //8.已移动到的区域颜色
//    slider.minimumTrackTintColor = [UIColor grayColor];
    //9.未移动到的区域颜色
//    slider.maximumTrackTintColor = [UIColor greenColor];
    //10.滑块的颜色
//    [slider setThumbTintColor:[UIColor cyanColor]];
    //11.划过区域的颜色
//    [slider setTintColor:[UIColor redColor]];
    //12.设置滑块的图片
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb@2x"] forState:UIControlStateNormal];
    //13.设置左右两边的图片
    [slider setMaximumTrackImage:[UIImage imageNamed:@"player_slider_playback_right@2x"] forState:UIControlStateNormal];
    [slider setMinimumTrackImage: [UIImage imageNamed:@"player_slider_playback_left@2x"] forState:UIControlStateNormal];
    
    [self.view addSubview:slider];
    
    /* 三.UISegment */
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"first", @"second", @"third"]];
    //segment 不给frame 系统会自动计算大小
    NSLog(@"%@", NSStringFromCGRect(segment.frame));
    //1.momentary yes 的时候 点击没有选中的效果 默认为no 点击后显示选中
    segment.momentary = YES;
    //2.numberOfSegments
    NSUInteger numberOfSegments = segment.numberOfSegments;
    NSLog(@"个数:%lu", numberOfSegments);
    segment.tag = 100;
    //3.插入segment insertSegmentWithTitle
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 200, 120, 40);
    [self.view addSubview:button];
    button.backgroundColor = [UIColor greenColor];
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:segment];
    //4.移除
    //5.settitle
    [segment setTitle:@"huangxiao" forSegmentAtIndex:0];
    //6.setwidth
    [segment setWidth:0 forSegmentAtIndex:0];
    //7.setContentOffset设置对应下标内容的偏移
//    segment setContentOffset: forSegmentAtIndex:
    [segment setContentOffset:CGSizeMake(20, 0) forSegmentAtIndex:1];
    //8.能否被选中
    [segment setEnabled:NO forSegmentAtIndex:0];
//    9.selectedSegmentIndex = 1
    segment.selectedSegmentIndex = 0;
    //10.tintColor文字及边框颜色
    segment.tintColor = [UIColor whiteColor];
    //11.如果分段控制的段宽为0时 并且该属性是yes时 系统会自动计算 默认为no
    segment.apportionsSegmentWidthsByContent = YES;
    //12.绑定事件
    [segment addTarget:segment action:@selector(handleSegment:) forControlEvents:UIControlEventValueChanged];
    
    /* 四.UIPageControl */
    UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(20, 300, 200, 30)];
    //1.分页控制器的页数 默认为0
    page.numberOfPages = 9;
    //2.当前页
    page.currentPage = 0;
    //3.当只有一页时 隐藏
    page.hidesForSinglePage = NO;
    //4.获取点的大小
    CGSize size = [page sizeForNumberOfPages:1];
    NSLog(@"%@", NSStringFromCGSize(size));
    //5.未选中页的默认颜色
    page.pageIndicatorTintColor = [UIColor greenColor];
    //6.当前页的颜色
    page.currentPageIndicatorTintColor = [UIColor blackColor];
    //7.绑定事件
    [page addTarget:self action:@selector(handlePage:) forControlEvents:UIControlEventValueChanged];
    page.backgroundColor = [UIColor redColor];
    //8.关闭系统事件page的切换, 直到调用updateCurrentPageDisplay的方法才会显示
//    page.updateCurrentPageDisplay
    [self.view addSubview:page];
}
- (void)handleButton:(UIButton *)button
{
    UISegmentedControl *segment = [self.view viewWithTag:100];
    [segment insertSegmentWithTitle:@"222" atIndex:1 animated:YES];
}

- (void)switcAction:(UISwitch *)swit
{
    //根据switch的状态 决定触发什么样的事件
    if (swit.on == YES) {
        NSLog(@"ON");
    } else {
    NSLog(@"关");
    }
}
- (void)SliderAcion:(UISlider *)slider
{
    NSLog(@"%f", slider.value);
}
- (void)handleSegment:(UISegmentedControl *)segment
{
    NSLog(@"%ld", segment.selectedSegmentIndex);//内用switch
}
- (void)handlePage:(UIPageControl *)page
{
    NSLog(@"change");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
